package com.example.alarmclock;

import android.app.Dialog;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.NumberPicker;
import android.widget.Toast;

public class DelayDialogFragment extends DialogFragment {

    private NumberPicker numberPicker;

    @NonNull
    @Override
    public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = requireActivity().getLayoutInflater();
        View view = inflater.inflate(R.layout.dialog_delay, null);
        builder.setView(view)
                .setTitle("选择延迟时间")
                .setPositiveButton("确定", (dialog, which) -> {
                    int delayMinutes = numberPicker.getValue();
                    ((AlarmAlertActivity) getActivity()).snoozeAlarm(delayMinutes);
                })
                .setNegativeButton("取消", (dialog, which) -> dismiss());

        numberPicker = view.findViewById(R.id.number_picker);
        numberPicker.setMinValue(1);
        numberPicker.setMaxValue(60);
        numberPicker.setValue(5); // Default value

        return builder.create();
    }
}



